home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROCS.ZIP / DOSFILES.ICN < prev    next >
Text File  |  1992-09-28  |  2KB  |  66 lines

  1. ############################################################################
  2. #
  3. #    File:     dosfiles.icn
  4. #
  5. #    Subject:  Procedures to get MS-DOS file names
  6. #
  7. #    Author:   Paul Abrahams
  8. #
  9. #    Date:     September 24, 1990
  10. #
  11. ###########################################################################
  12. #
  13. #  dosfiles(pfn) accepts a DOS filename possibly containing wildcards.
  14. #  The filename can also include a drive letter and path.
  15. #  If the filename ends in "\" or ":", "*.*" is appended.
  16. #  The result sequence is a sequence of the filenames corresponding to pfn.
  17. ############################################################################
  18. #
  19. #  Requires: MS-DOS extensions
  20. #
  21. ############################################################################
  22.  
  23. procedure dosfiles(pfn)
  24.    local asciiz, fnr, prefix, k, name
  25.    local ds, dx, result, fnloc, string_block
  26.  
  27. # Get Disk Transfer Address; filename locn is 30 beyond that.
  28.  
  29.    result := Int86([16r21, 16r2f00] ||| list(7,0))
  30.    fnloc := 16 * result[8] + result[3]+ 30
  31.  
  32. # Get the generalized filename.
  33.  
  34.    fnr := reverse(pfn)
  35.    k := upto("\\:", fnr) | *fnr + 1
  36.    prefix := reverse(fnr[k:0])
  37.    name := "" ~== reverse(fnr[1:k]) | "*.*"
  38.  
  39. # Get the first file in the sequence.
  40.  
  41.    asciiz := prefix || name || "\x00"
  42.    Poke(string_block := GetSpace(*asciiz), asciiz)
  43.    ds := string_block / 16
  44.    dx := string_block % 16
  45.    result := Int86([16r21, 16r4e00, 0, 0, dx, 0, 0, 0, ds])
  46.    case result[2] of {
  47.       0 : {}
  48.       18 : fail
  49.       default : stop("i/o error ", result[2])
  50.       }
  51.    suspend prefix || extract_name(fnloc)
  52.  
  53. # Get the remaining files in the sequence.
  54.  
  55.    while Int86([16r21, 16r4f00, 0, 0, 0, 0, 0, 0, 0])[2] = 0 do
  56.       suspend prefix || extract_name(fnloc)
  57. end
  58.  
  59. procedure extract_name(fnloc)
  60.    local asciiz
  61.    asciiz := Peek(fnloc, 13)
  62.    return asciiz[1:upto("\x00", asciiz)]
  63. end
  64.